package com.atguign.gulimall.product.web;

import com.atguign.gulimall.product.entity.CategoryEntity;
import com.atguign.gulimall.product.service.CategoryService;
import com.atguign.gulimall.product.vo.Catalog2Vo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * @program: gulimall
 * @description: 跳转页面
 * @author: liuxvru
 * @create: 2024-03-06 17:54
 **/
@Slf4j
@Controller
public class IndexController {

    @Autowired
    CategoryService categoryService;
    @GetMapping({"/","index.html"})
    public String indexPage(Model mode, HttpSession session){
        log.debug(session.getId());
        List<CategoryEntity> categoryEntityList= categoryService.getLevel1Categorys();
        mode.addAttribute("categorys",categoryEntityList);
        return "index";
    }
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String,List<Catalog2Vo>> getCategoryService() {
        return categoryService.getCatalogJson();
    }
}
